
<!DOCTYPE html>
<html lang="zh">
<head>
  <meta charset="UTF-8">
  <title>JS 算法交互示例</title>
  <style>
    body { font-family: Arial, sans-serif; padding: 20px; }
    input, button { margin: 5px; padding: 5px; }
    #result { margin-top: 10px; font-weight: bold; color: blue; }
  </style>
</head>
<body>
  <h2>最大公约数计算器</h2>
  <label>数字 A: <input type="number" id="numA"></label><br>
  <label>数字 B: <input type="number" id="numB"></label><br>
  <button onclick="computeGCD()">计算 GCD</button>

  <div id="result"></div>

  <script>
    // 辗转相除法求最大公约数
    function gcd(a, b) {
      while (b !== 0) {
        let temp = b;
        b = a % b;
        a = temp;
      }
      return a;
    }

    function computeGCD() {
      let a = parseInt(document.getElementById("numA").value);
      let b = parseInt(document.getElementById("numB").value);

      if (isNaN(a) || isNaN(b)) {
        document.getElementById("result").innerText = "请输入两个数字！";
        return;
      }

      let result = gcd(a, b);
      document.getElementById("result").innerText = `最大公约数是：${result}`;
    }
  </script>
</body>
</html>
